package com.jxb.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

import com.jxb.service.UserInterface;
import com.jxb.service.UserService;

/**
 * 类注释
 *
 * @author jiaobo
 * @date Created in 2024/11/24 16:04
 **/
public class JdkTest {

    public static void main(String[] args) {
        UserService target = new UserService();
        Object proxyInstance = Proxy.newProxyInstance(UserService.class.getClassLoader(),
                                          new Class[] {UserInterface.class},
                                          new InvocationHandler() {
                                              @Override
                                              public Object invoke(Object proxy, Method method, Object[] args)
                                                      throws Throwable {
                                                  System.out.println("before ... ...");
                                                  Object result = method.invoke(target, args);
                                                  System.out.println("after ... ...");
                                                  return result;
                                              }
                                          });
        UserInterface user = (UserInterface) proxyInstance;
        user.test();
    }

}
